package net.peelmeagrape.hibernate;

import net.peelmeagrape.hibernate.xmlgen.XmlAttribute;
import net.peelmeagrape.hibernate.xmlgen.XmlElement;
import net.peelmeagrape.hibernate.xmlgen.ChildElement;
import net.peelmeagrape.hibernate.collections.Key;
import net.peelmeagrape.hibernate.sql.SqlDelete;
import net.peelmeagrape.hibernate.sql.SqlUpdate;
import net.peelmeagrape.hibernate.sql.SqlInsert;

import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * A join allows some properties of a class to be persisted to a second table. These
 * properties should be identified using the
 * {@link net.peelmeagrape.hibernate.Property#join()} value, which should match
 * the value of {@link #table()}. Table joins should be listed in the
 * {@link net.peelmeagrape.hibernate.H8Class#join()} element.
 */
@Retention(RUNTIME)
@XmlElement(name="join")
public @interface Join
{
    @XmlAttribute String table();

    /**
     * Override the schema name specified by the root &lt;hibernate-mapping&gt; element.
     */
    @XmlAttribute String schema() default "";

    /**
     * Override the catalog name specified by the root &lt;hibernate-mapping&gt; element.
     */
    @XmlAttribute String catalog() default "";

    @XmlAttribute String subselect() default "";

    @XmlAttribute FetchSetting fetch() default FetchSetting.JOIN;
    @XmlAttribute boolean inverse() default false;
    @XmlAttribute boolean optional() default false;

    @ChildElement(2) Comment[] comment() default {};

    @ChildElement(3) Key key();

    //todo: ordering of property|many-to-one etc. before sql-insert
    @ChildElement(20) SqlInsert[] sqlInsert() default {};
    @ChildElement(21) SqlUpdate[] sqlUpdate() default {};
    @ChildElement(22) SqlDelete[] sqlDelete() default {};
}
